package system.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import system.dto.LoginDto;
import system.form.LoginForm;
import system.logic.LoginLogic;
import system.value.LoginValue;

public class LoginAction extends Action{
	public ActionForward execute(final ActionMapping mapping,
            final ActionForm form, final HttpServletRequest request,
            final HttpServletResponse response){
		LoginForm l_form = (LoginForm) form;
		LoginDto l_dto = new LoginDto();
		LoginLogic l_loginLogic = new LoginLogic();
		
		if("login".equals(l_form.getButtonId())) {
			l_dto.setLoginValue(l_form.getLoginValue());
			try {
				l_loginLogic.checkLogin(l_dto);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				System.out.println("err");
				e.printStackTrace();
			}
			l_form.setLoginValue(l_dto.getLoginValue());
			LoginValue l_value = l_form.getLoginValue();
			if("2".equals(l_value.getFlag())) {
				return mapping.findForward("login");
			}else{
				return mapping.getInputForward();
			}
		}else{
			return mapping.getInputForward();
		}
	}
}
